﻿using BaseData.DomainLib.AggregatesModel.MaterialCategoryAggregate;
using Microsoft.EntityFrameworkCore;
using Swimj.DomainLib.SeedWork;

namespace BaseData.InfrastructureLib.Repositories
{
    public class MaterialCategoryRepository : IMaterialCategoryRepository
    {
        private readonly BaseDataDbContext _productMaterialDbContext;
        public IUnitOfWork UnitOfWork => _productMaterialDbContext;

        public MaterialCategoryRepository(BaseDataDbContext productMaterialDbContext)
        {
            _productMaterialDbContext = productMaterialDbContext;
        }

        public MaterialCategory Add(MaterialCategory materialCategory)
        {
            return _productMaterialDbContext.MaterialCategories.Add(materialCategory).Entity;
        }

        public async Task<MaterialCategory?> Get(int id)
        {
            return await _productMaterialDbContext.MaterialCategories.FirstOrDefaultAsync(c => c.Id == id);
        }
    }
}